# R Options
options(stringsAsFactors=FALSE)

# Required libraries
library(Seurat) # main
library(ggplot2) # plots
library(patchwork) # combination of plots
library(magrittr) # %>% operator

# Other libraries we use
# Knit: knitr
# Data handling: dplyr, tidyr, purrr
# Tables: kableExtra
# Plots: ggsci

# Source plotting functions
source("R/functions_io.R")
source("R/functions_plotting.R")
source("R/functions_analysis.R")
source("R/functions_util.R")

# Knitr default options
knitr::opts_chunk$set(echo=TRUE, cache=FALSE, message=FALSE, warning=FALSE, fig.width=10)
hto_colours = list()
hto_colours$col_hto_global = ggsci::pal_npg()(3)
hto_colours$col_hto_all = ggsci::pal_npg()(factorial(length(params$hto_names)) + 1)
hto_colours$col_hto_collapsed = ggsci::pal_npg()(length(params$hto_names) + 2)
hto_levels = c("Negative", "Doublet", params$hto_names[length(params$hto_names):1])
names(hto_colours$col_hto_collapsed) = hto_levels
if (!file.exists(params$path_out)) dir.create(params$path_out, recursive=TRUE)

Read input data

In this first section of the report, we read 10X data from the files produced by CellRanger:

and setup a Seurat object. This object includes different data types in separate assays:

Note that ‘Antibody Capture’ features can correspond to ‘HTO’ and ‘ADT’ and are distinguished based on provided HTO names.

Dataset summary
Assay CellsTotal CellsWithHtoReads CellsWithoutHtoReads
RNA 16916 16916 0

Demutliplexing with hashtag oligos (HTOs)

This section of the report shows how cells are assigned to their sample-of-origin.

Normalisation of HTO counts

We start the analysis by normalising raw HTO counts. HTO counts for each cell are divided by the total counts for that cell and multiplied by 10,000. This is then natural-log transformed.

Visualisation of raw and normalised HTO data

This section of the report visualises raw and normalised HTO data to understand whether the demultiplexing step has worked well.

Pairs of raw (top) and normalised (bottom) HTO counts are visualised to confirm mutal exclusivity in singlet cells. Data points correspond to measured HTO counts per HTO, colours correspond to the assigned samples-of-origin.

The following ridge plots visualise the enrichment of assigned sample-of-origin for the respective normalised HTO counts.

Lastly, we compare the number of features between classified cells.

Remove cells classified as doublet or negative

This section of the report states the number of cells that remain after negative and doublet cells are removed.

## An object of class Seurat 
## 18984 features across 13843 samples within 2 assays 
## Active assay: RNA (18976 features, 0 variable features)
##  1 other assay present: HTO

Preliminary visualisation of demultiplexed RNA data

This section of the report provides first insights into your RNA dataset based on a preliminary pre-processing of the RNA data using the standard scRNA-seq workflow.

Visualisation with UMAP

We use a UMAP to visualise and explore a dataset. The goal is to place similar cells together in 2D space, and learn about the biology underlying the data. Cells are color-coded according to the assigned sample-of-origin.

Take care not to mis-read a UMAP:

  • Parameters influence the plot (we use defaults here)
  • Cluster sizes relative to each other mean nothing, since the method has a local notion of distance
  • Distances between clusters might not mean anything
  • You may need more than one plot

For a nice read to intuitively understand UMAP, see https://pair-code.github.io/understanding-umap/.

Write out demultiplexed data

Finally, demultiplexed RNA data are written back to file.

Parameter table

The following parameters were used to run the workflow.

Name Value
project_id HTO_testDataset
path_data test_datasets/10x_pbmc_hto_GSE108313/counts
path_out test_datasets/10x_pbmc_hto_GSE108313/demultiplexed
hto_names htoA=htoA, htoB=htoB, htoC=htoC, htoD=htoD, htoE=htoE, htoF=htoF, htoG=htoG, htoH=htoH
mt_names ^MT-
col palevioletred
downsample_cells_n

Software versions

This report was generated using the scrnaseq GitHub repository. Software versions were collected at run time.

Name Version
ktrns/scrnaseq 94536c83158fd9a9cc989fc27639fcd95d300385
R R version 3.6.1 (2019-07-05)
Platform x86_64-apple-darwin15.6.0 (64-bit)
Operating system macOS Mojave 10.14.6
Packages ape5.3, assertthat0.2.1, backports1.1.5, bitops1.0-6, caTools1.17.1.3, cli2.0.2, cluster2.1.0, codetools0.2-16, colorspace1.4-1, cowplot1.0.0, crayon1.3.4, data.table1.12.6, digest0.6.25, dplyr0.8.3, evaluate0.14, fansi0.4.0, farver2.0.1, fitdistrplus1.0-14, future1.15.1, future.apply1.3.0, gdata2.18.0, ggplot23.2.1, ggrepel0.8.1, ggridges0.5.1, ggsci2.9, globals0.12.5, glue1.4.1, gplots3.0.1.1, gridExtra2.3, gtable0.3.0, gtools3.8.1, highr0.8, hms0.5.2, htmltools0.4.0, htmlwidgets1.5.1, httr1.4.1, ica1.0-2, igraph1.2.4.2, irlba2.3.3, jsonlite1.6.1, kableExtra1.1.0, KernSmooth2.23-16, knitr1.26, labeling0.3, lattice0.20-38, lazyeval0.2.2, leiden0.3.1, lifecycle0.1.0, listenv0.8.0, lmtest0.9-37, lsei1.2-0, magrittr1.5, MASS7.3-51.4, Matrix1.2-18, munsell0.5.0, nlme3.1-142, npsurv0.4-0, patchwork1.0.0, pbapply1.4-2, pillar1.4.2, pkgconfig2.0.3, plotly4.9.1, plyr1.8.4, png0.1-7, purrr0.3.3, R.methodsS31.7.1, R.oo1.23.0, R.utils2.9.2, R62.4.1, RANN2.6.1, RColorBrewer1.1-2, Rcpp1.0.3, RcppAnnoy0.0.14, RcppParallel4.4.4, readr1.3.1, reshape21.4.3, reticulate1.13, rlang0.4.6, rmarkdown1.18, ROCR1.0-7, RSpectra0.16-0, rstudioapi0.11, rsvd1.0.2, Rtsne0.15, rvest0.3.5, scales1.1.0, sctransform0.2.0, sessioninfo1.1.1, Seurat3.1.5, stringi1.4.3, stringr1.4.0, survival3.1-8, tibble2.1.3, tidyr1.0.0, tidyselect0.2.5, tsne0.1-3, uwot0.1.5, vctrs0.2.0, viridisLite0.3.0, webshot0.5.2, withr2.1.2, xfun0.11, xml21.2.2, yaml2.2.0, zeallot0.1.0, zoo1.8-6